import { defHttp } from '/@/utils/http/axios';
import { LoginDto, LoginResultDto, UacUserInfoDto } from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/demo/uac/login',
  // Logout = '/logout',
  Logout = '/demo/uac/logout',
  GetUserInfo = '/demo/uac/userinfo',
  GetPermCode = '/getPermCode',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginDto, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultDto>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      //使用mock或测试地址时，可通过设置apiUrl使用.env中配置的VITE_PROXY不同别名
      // apiUrl: '/mock-api',
      //使用mock或测试接口时，如返回的直接为数据，不包含渠成网关中统一定义的code和msg，可通过设置isQuChengGatewayUnifyFormat为false
      // isQuChengGatewayUnifyFormat: false,
      //可选参数
      // joinParamsToUrl: true,
      // joinTime: false,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<UacUserInfoDto>(
    { url: Api.GetUserInfo },
    {
      errorMessageMode: 'none',
      // apiUrl: '/mock-api',
      // isQuChengGatewayUnifyFormat: false,
    },
  );
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get<string>(
    { url: Api.Logout },
    {
      // apiUrl: '/mock-api',
    },
  );
}
